package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MaintenancePlans;
import com.ruoyi.system.domain.vo.MaintenancePlansVo;
import com.ruoyi.system.service.IMaintenancePlansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备保养计划管理Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/plans")
public class MaintenancePlansController extends BaseController {
    @Autowired
    private IMaintenancePlansService maintenancePlansService;

    /**
     * 查询设备保养计划管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:plans:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaintenancePlans maintenancePlans) {
        startPage();
        List<MaintenancePlansVo> list = maintenancePlansService.selectMaintenancePlansList(maintenancePlans);
        return getDataTable(list);
    }

    /**
     * 导出设备保养计划管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:plans:export')")
    //@Log(title= "设备保养计划管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintenancePlans maintenancePlans) {
        List<MaintenancePlansVo> list = maintenancePlansService.selectMaintenancePlansList(maintenancePlans);
        ExcelUtil<MaintenancePlansVo> util = new ExcelUtil<MaintenancePlansVo>(MaintenancePlansVo.class);
        util.exportExcel(response, list, "设备保养计划管理数据");
    }

    /**
     * 获取设备保养计划管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:plans:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId) {
        return success(maintenancePlansService.selectMaintenancePlansByPlanId(planId));
    }

    /**
     * 新增设备保养计划管理
     */
    //@PreAuthorize("@ss.hasPermi('system:plans:add')")
    //@Log(title= "设备保养计划管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaintenancePlans maintenancePlans) {
        return toAjax(maintenancePlansService.insertMaintenancePlans(maintenancePlans));
    }

    /**
     * 修改设备保养计划管理
     */
    //@PreAuthorize("@ss.hasPermi('system:plans:edit')")
    //@Log(title= "设备保养计划管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaintenancePlans maintenancePlans) {
        return toAjax(maintenancePlansService.updateMaintenancePlans(maintenancePlans));
    }

    /**
     * 删除设备保养计划管理
     */
    //@PreAuthorize("@ss.hasPermi('system:plans:remove')")
    //@Log(title= "设备保养计划管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds) {
        return toAjax(maintenancePlansService.deleteMaintenancePlansByPlanIds(planIds));
    }
}
